package ModelLayer;


/**
 * Description:
 * This class represents the product of the company 
 * all of the fields are connected with the products features and parameters.
 * @author (Georgi Georgiev) 
 * @version (09.12.2013)
 */
public class Product
{
    private String art_nr;
    private String name;
    private String category;
    private String department;
    private double price;
    private double price_for_palette;
    private int pieces_in_palette;
    private int quantity;
    private int maximum_amount;
    private int minimum_amount;
    private int amount_qualified_for_discount;
    private String group_nr;
    private double discount;
    
    /**
     * Constructor for objects of class Product
     * It assignes provided data to attributes of Product class
     */
    public Product(String i_art_nr, String i_name, String i_caregory, String i_department, double i_price, double i_price_for_palette, int i_pieces_in_palette, int i_quantity, int  i_maximum_amount, int i_minimum_amount, int i_amount_qualified_for_discount, String i_group_nr, double i_discount)
    {
        art_nr = i_art_nr;
        name = i_name;
        category = i_caregory;
        department = i_department;
        price = i_price;
        price_for_palette = i_price_for_palette;
        pieces_in_palette = i_pieces_in_palette;
        quantity = i_quantity;
        maximum_amount = i_maximum_amount;
        minimum_amount = i_minimum_amount;
        amount_qualified_for_discount = i_amount_qualified_for_discount;
        group_nr = i_group_nr;
        discount = i_discount;
    }

    /**********************************************************************************GETTERS**********************************************************************************************/
    
    /**
     * Returns product's articule number.
     */
    public String get_art_nr()
    {
        return art_nr;
    }  
    
    /**
     * Returns product's name.
     */
    public String get_name()
    {
        return name;
    }
    
    /**
     * Returns product's categoy.
     */
    public String get_category()
    {
        return category;
    }
    
    /**
     * Returns product's current location(the department where it is located).
     */
    public String get_department()
    {
        return department;
    }
    
    /**
     * Returns product's price.
     */
    public double get_price()
    {
        return price;
    }
    
    /**
     * Returns product's price for a single palette.
     */
    public double get_price_for_palette()
    {
        return price_for_palette;
    }
    
    /**
     * Returns how many pieces of the product are in single palette.
     */
    public int get_pieces_in_palette()
    {
        return pieces_in_palette;
    }
    
    /**
     * Returns the number of the Products(in stock)
     */
    public int get_quantity()
    {
        return quantity;
    }  
    
    /**
     * Returns the maximum amount of the product, that can be stored in the warehouse. 
     */
    public int get_maximum_amount()
    {
        return maximum_amount;
    }
    
    /**
     * Returns the minimum amount of the product, that can be stored in the warehouse.
     */
    public int get_minimum_amount()
    {
        return minimum_amount;
    }
    
    public String get_group_nr()
    {
        return group_nr;
    }
    
    /**
     * Returns the amout of qualified discount for large number of ordered products.
     */
    public int get_amount_qualified_for_discount()
    {
        return amount_qualified_for_discount;
    }
    
    public double get_discount()
    {
        return discount;
    }
    
    /**********************************************************************************SETTERS**********************************************************************************************/

    /**
     * Changes product's name.
     */
    public void set_name(String i_name)
    {
        name = i_name;
    }
    
    /**
     * Changes product's categoy.
     */
    public void set_category(String i_category)
    {
        category = i_category;
    }
    
    /**
     * Changes product's department(location).
     */
    public void set_department(String i_department)
    {
        department = i_department;
    }
    
    /**
     * Changes product's price.
     */
    public void set_price(double i_set_price)
    {
        price = i_set_price;
    }
    
    /**
     * Changes's product's price for single palette.
     */
    public void set_price_for_palette(double i_price_for_palette)
    {
        price_for_palette = i_price_for_palette;
    }
    
    /**
     * Changes product's amount of pieces in palette.
     */
    public void set_pieces_in_palette(int i_pieces_in_palette)
    {
        pieces_in_palette = i_pieces_in_palette;
    }    
    
    /**
     * Changes products's quantity.
     */
    public void set_quantity(int i_quantity)
    {
        quantity = i_quantity;
    }
    
    /**
     * Changes product's maximum amount in the warehouse.
     */
    public void set_maximum_amount(int i_maximum_amount)
    {
        maximum_amount = i_maximum_amount;
    }
    
    /**
     * Changes product's minimum amount in the warehouse.
     */
    public void set_minimum_amount(int i_minimum_amount)
    {
        minimum_amount = i_minimum_amount;
    }
    
    /**
     * Changes product's amount of discount.
     */
    public void set_amount_qualified_for_discount(int i_amount_qualified_for_discount)
    {
        amount_qualified_for_discount = i_amount_qualified_for_discount;
    }
    
    public void set_group_nr(String input)
    {
        group_nr = input;
    }
    
    public void set_discount(double input)
    {
        discount = input;
    }
    
    /**********************************************************************************OTHER METHODS**********************************************************************************************/
    
    /**
     * This method returns all attributes of Product class as a single String.
     * Attributes are separated with single tabulations.
     */
    public String give_string_data()
    {
        return String.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s", art_nr, name, category, department, price, price_for_palette, pieces_in_palette, quantity, maximum_amount, minimum_amount, amount_qualified_for_discount, group_nr, discount);
    }
    
    public Object[] give_array()
    {
    	Object[] attributes = { Integer.parseInt(art_nr), name, quantity, category, amount_qualified_for_discount, department, price };
    	return attributes;
    }
    
    /**
     * Method to print all of the product's fields
     */
    public String printable()
    {
        String str_discount = "" + discount + "%";
        if(department.equals("KB") && !(group_nr.equals("0")))
        {
            return String.format("Articule Number:\t\t\t%s \nProduct name:\t\t\t\t%s \nProduct category:\t\t\t%s \nProduct department:\t\t\t%s \nProduct's price:\t\t\t%s \nProduct's price for palette:\t\t%s \nAmount of products in palette:\t\t%s \nQuantity of products:\t\t\t%s \nMaximum amount in stock:\t\t%s \nMinimum amount in stock:\t\t%s \nAmount required for discount:\t\t%s \nGroup number:\t\t\t\t%s \nDiscount:\t\t\t\t%s \n", art_nr, name, category, department, price, price_for_palette, pieces_in_palette, quantity, maximum_amount, minimum_amount, amount_qualified_for_discount, group_nr, str_discount);
        }
        return String.format("Articule Number:\t\t\t%s \nProduct name:\t\t\t\t%s \nProduct category:\t\t\t%s \nProduct department:\t\t\t%s \nProduct's price:\t\t\t%s \nProduct's price for palette:\t\t%s \nAmount of products in palette:\t\t%s \nQuantity of products:\t\t\t%s \nMaximum amount in stock:\t\t%s \nMinimum amount in stock:\t\t%s \nAmount required for discount:\t\t%s \nDiscount:\t\t\t\t%s \n", art_nr, name, category, department, price, price_for_palette, pieces_in_palette, quantity, maximum_amount, minimum_amount, amount_qualified_for_discount, str_discount);
    }
    
    public void subtract_amount(int amount)
    {
        quantity -= amount;
    }
    
    public boolean needs_restocking()
    {
        return quantity < minimum_amount;
    }
    
    public boolean is_unfinished()
    {
        return price == 0;
    }
    
    public String restocking_printable()
    {
        return String.format("Articule Number:\t\t\t%s \nAmount that needs to be restocked:\t%s \n", art_nr, (maximum_amount - quantity));
    }
}

